const joi = require('joi')

// 定义验证规则
const code = joi.string().pattern(/^\d{6}$/)
const phone = joi.string().pattern(/^1[3-9]\d{9}$/)
const name = joi.string().min(1).max(64)
const password = joi.string().min(6).max(16).alphanum()

// 商家添加分类验证规则、
const cate_name = joi.string().min(1).max(16).required()
const level = joi.string().valid('一级', '二级').required()
const super_id = joi.number()
const is_show = joi.boolean().valid(false, true).required()
const nav_show = joi.boolean().valid(false, true).required()

// 商家添加商品验证规则
const goods_name = joi.string().min(1).max(255).required()
const cate_id = joi.number().required()
const desc = joi.string().max(500).min(0)
const src = joi.string().dataUri().required()
const price = joi.number().min(0).required()
const count = joi.number().min(1).required()
const specs = joi.string().min(1).max(8).required()
const no = joi
  .string()
  .pattern(/^[A-Za-z]{1,}\d+$/)
  .max(64)
  .required()
const recommend = joi.boolean().required()
const is_new = joi.boolean().required()
const img_type = joi
  .string()
  .pattern(/^jpg$|^png$|^jpeg$|^gif$/)
  .required()

// 定义批量操作时多个商品id验证规则
const ids = joi
  .string()
  .pattern(/^\d+,?(\d+,?)*$/)
  .required()
const isNew = joi.boolean()
const is_recommend = joi.boolean()
const banner = joi.boolean().required()

// 删除订单的订单id
const id = joi.number().min(1).required()

// 批量操作订单选项参数
const option = joi.string().valid('deliver', 'delete').required()

// 筛选订单数据筛选条件
const orderNo = joi.string().alphanum().length(20)
const nameOrPhone = joi.string()
const OrderStatus = joi.number().valid(0, 1, 2, 3)
//#region
// 导出商家用户登录验证规则
exports.bus_user_login_schema = {
  body: {
    code,
    phone,
    name,
    password
  }
}

// 导出商家添加分类验证规则
exports.add_cate_schema = {
  body: {
    cate_name,
    level,
    super_id,
    is_show,
    nav_show
  }
}

// 商家添加商品验证规则
exports.add_goods_schema = {
  body: {
    name: goods_name,
    cate_id: cate_id,
    desc: desc,
    src: src,
    price: price,
    count: count,
    specs: specs,
    no: no,
    recommend: recommend,
    new: is_new,
    banner,
    img_type: img_type
  }
}

// 商家编辑商品验证规则
exports.edit_goods_schema = {
  body: {
    name: goods_name,
    cate_id: cate_id,
    desc: desc,
    price: price,
    count: count,
    specs: specs,
    no: no,
    recommend: recommend,
    new: is_new,
    banner
  }
}

// 切换商品是否是新品验证规则
exports.toggle_new_schema = {
  body: {
    is_new
  }
}
// 切换商品是否是推荐验证规则
exports.toggle_recommend_schema = {
  body: {
    recommend
  }
}

// 切换商品是否轮播图展示验证规则
exports.toggle_banner_schema = {
  body: {
    banner
  }
}
// 批量切换商品是否是新品或者是否是推荐验证规则
exports.toggle_new_recommend_schema = {
  body: {
    ids,
    is_new: isNew,
    is_recommend
  }
}
//#endregion

// 删除订单的订单id验证规则
exports.del_order_schema = {
  body: {
    id
  }
}
// 获取订单信息的订单id验证规则
exports.get_order_schema = {
  query: {
    id
  }
}
// 批量操作订单验证参数
exports.deal_order_option_schema = {
  body: {
    ids,
    option
  }
}

// 筛选订单数据筛选条件
exports.filter_order_list_schema = {
  params: {
    orderNo,
    nameOrPhone,
    OrderStatus
  }
}

// 筛选需要处理的订单数据信息
exports.filter_deal_order_schema = {
  params: {
    orderNo,
    nameOrPhone,
    OrderStatus: joi.number().valid(1)
  }
}

exports.order_deliver_schema = {
  body: {
    id
  }
}
